/**
 * 
 */
package com.gr.experimental.model.impl.distr;

class DescriptorImpl implements Descriptor {

	private String name;
	private Class<?> type;
	private DescriptorType descriptorType;
	private boolean modifiable;
	private Object constantValue;

	public DescriptorImpl(String name, Class<?> variableType, DescriptorType descriptorType, boolean modifiable) {
		this(name, variableType, descriptorType, modifiable, null);
	}
	
	public DescriptorImpl(String name, Class<?> variableType, DescriptorType descriptorType, boolean modifiable, Object constantValue) {
		this.name = name;
		this.type = variableType;
		this.descriptorType = descriptorType;
		this.modifiable = modifiable;
		if (!modifiable && constantValue == null) {
			throw new IllegalArgumentException("constant value has to be set for unmodifiable variables");
		}
		if (modifiable && constantValue != null) {
			throw new IllegalArgumentException("constant value may not be set for modifiable variables");
		}
		this.constantValue = constantValue;
	}

	@Override
	public Class<?> getType() {
		return type;
	}

	@Override
	public DescriptorType getDescriptorType() {
		return descriptorType;
	}

	@Override
	public String getSymbolName() {
		return name;
	}

	@Override
	public boolean isModifiable() {
		return modifiable;
	}

	/**
	 * {@inheritDoc}
	 * @see com.gr.experimental.model.impl.distr.Descriptor#getConstantValue()
	 */
	@Override
	public Object getConstantValue() {
		return constantValue;
	}

}